Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gnovm): Fix panic when calling len()/cap() on pointer array #2709

Merged
merged 9 commits into from
Sep 13, 2024

Conversation

notJoon
Copy link
Member

@notJoon notJoon commented Aug 19, 2024

Description

closes #2707

The GetLength(), GetCapacity() method in TypedValue has been updated to handle pointer type.

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Aug 19, 2024
Copy link

codecov bot commented Aug 19, 2024

Codecov Report

Attention: Patch coverage is 58.33333% with 15 lines in your changes missing coverage. Please review.

Project coverage is 60.84%. Comparing base (11d29a2) to head (044054d).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
gnovm/pkg/gnolang/values.go 58.33% 12 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2709      +/-   ##
==========================================
- Coverage   60.85%   60.84%   -0.01%     
==========================================
  Files         563      563              
  Lines       75169    75190      +21     
==========================================
+ Hits        45741    45749       +8     
- Misses      26062    26073      +11     
- Partials     3366     3368       +2     
Flag Coverage Δ
contribs/gnodev 60.65% <ø> (-0.82%) ⬇️
contribs/gnofaucet 14.46% <ø> (ø)
gno.land 67.21% <ø> (ø)
gnovm 65.63% <58.33%> (+0.04%) ⬆️
misc/genstd 80.54% <ø> (ø)
misc/logos 19.88% <ø> (-0.36%) ⬇️
tm2 62.05% <ø> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MikaelVallenet
Copy link
Contributor

MikaelVallenet commented Aug 19, 2024

Hello, @notJoon thanks for the fix 🙏, Can you fix the cap function that suffers from the same problem too

func main() {
	exp := [...]string{"HELLO"}
	x := cap(&exp)
	println(x)
}

@notJoon
Copy link
Member Author

notJoon commented Aug 19, 2024

Hello, @notJoon thanks for the fix 🙏, Can you fix the cap function that suffers from the same problem too

modified the cap function in the same way. I had forgotten this function. thanks @MikaelVallenet

a089650

@notJoon notJoon changed the title fix(gnovm): Fix panic when calling len() on pointer array fix(gnovm): Fix panic when calling len()/cap() on pointer array Aug 19, 2024
Copy link
Contributor

@deelawn deelawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix Joon. Can you also make these changes in the if tv.V == nil blocks so that something like this won't crash the VM?

package main

func main() {
	printLen(nil)
}

func printLen(arr *[2]int) {
	println(len(arr))
}

@notJoon
Copy link
Member Author

notJoon commented Aug 20, 2024

Can you also make these changes in the if tv.V == nil blocks so that something like this won't crash the VM?

I just added a PointerType handler for the array case when tv.V is nil in the GetLength and GetCapacity functions. Thanks for catch @deelawn 👍

Copy link
Contributor

@deelawn deelawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work 💪

gnovm/pkg/gnolang/uverse_test.go Outdated Show resolved Hide resolved
gnovm/pkg/gnolang/values.go Outdated Show resolved Hide resolved
@thehowl thehowl merged commit 2e56ecf into gnolang:master Sep 13, 2024
119 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

[GnoVM] - Cannot use pointer of an array as parameters of len & cap function
4 participants